<?php
/**
 +--------------------------------
 * RefundAction.class.php （用户退款）
 * date:2013.12.16
 * @author tanbin
 +--------------------------------
 *
 */
class ActivityAction extends BaseAction {
	protected $money;
	function _initialize() {
		parent::_initialize ();		
		$this->dao = M('Activity');
	}
	
	/*
	 * 活动记录列表
	 * */
	function index(){
		$where = array();
		$where = parent::create_where($where);
		$count = $this->dao->where($where)->count();
		if($count){
			$page=new Page($count,$this->listrows);
			$list = $this->dao->where($where)->order($this->order)->limit($page->firstRow.','.$page->listRows)->select();
			$this->assign('list',$list);
		}
		$this->assign("totalCount",$count);
		$this->assign('where',$where);
		$this->display();
	}	
	
	function edit(){ 
		$id = $_REQUEST['id'];
		if($id){
			$info = $this->dao->find($id);
			$this->assign('info',$info);
		}
		$this->display();
	}
	
	/**
	 * 保存活动信息
	 * @author tb
	 * @date 2014-03-11
	 * **/
	function save(){
		$data = $_REQUEST['data'];	
		$data['start_time'] = gettime($data['start_time']);
		$data['end_time'] = gettime($data['end_time']);
		$data['userid'] = $this->userid;
		if($data['id']){
			$res = $this->dao->save($data);
		}else{		
			$data['ctime'] = gettime(date("Y-m-d H:i:s"));
			$res = $this->dao->add($data);
		}
		
		if($res === FALSE){
			$this->_ajm(300,'保存失败！');
		}else{
			$this->_ajm(200,'保存成功！');
		}
	}
	
	
}
	
